<template>
	<div>
		<Row :gutter="10">
			<i-col span="8" v-for="(infor, i) in inforCardData" :key="`infor-${i}`" style="height: 120px;">
				<infor-card shadow :color="infor.color" :icon="infor.icon" :icon-size="36">
					<count-to :end="infor.count" count-class="count-style" />
					<p>{{ infor.title }}</p>
				</infor-card>
			</i-col>
		</Row>
		
		
		<div style="background:#eee;padding: 20px">
        <Card :bordered="false">
            <p slot="title">操作</p>
	            <ul>
	            <li style="list-style-type:none;margin-bottom: 20px;">
	                <a @click="doNew($event)" data-type = "gcash_index">车主提现申请</a>
	            </li>
	             <li style="list-style-type:none;margin-bottom: 20px;">
	                <a @click="doNew($event)" data-type = "bill_index">账单明细</a>
	            </li>
	             <li style="list-style-type:none;margin-bottom: 20px;">
	                <a @click="doNew($event)" data-type = "refund_index">会员退款</a>
	            </li>
	             <li style="list-style-type:none;margin-bottom: 20px;">
	                <a @click="doNew($event)" data-type = "user">会员充值</a>
	            </li>
	        	</ul>
        </Card>
    </div>
    
    <div style="background:#eee;padding: 20px">
        <Card :bordered="false">
            <p slot="title">邀请码</p>
	            <ul>
	            <li style="list-style-type:none;margin-bottom: 20px;text-align:center;">
	                <img width="200px" height="200px" :src="inviteData.qr">
	                <p style="font-size: 30px;color: red">{{inviteData.code_sn}}</p>
	            </li>
	        	</ul>
        </Card>
    </div>
		<!--<Row :gutter="20" style="margin-top: 20px;">
      <i-col span="8">
        <Card shadow>
          <chart-pie style="height: 300px;" :value="pieData" text="用户访问来源"></chart-pie>
        </Card>
      </i-col>
      <i-col span="16">
        <Card shadow>
          <chart-bar style="height: 300px;" :value="barData" text="每周用户活跃量"/>
        </Card>
      </i-col>
    </Row>-->
		<!--<Row style="margin-top: 20px;">
      <Card shadow>
        <example style="height: 310px;"/>
      </Card>
    </Row>-->
	</div>
</template>

<script>
	import InforCard from '_c/info-card'
	import CountTo from '_c/count-to'
	import { ChartPie, ChartBar } from '_c/charts'
	import Example from './example.vue'
	import {
		getMoney,
		getCode
	} from '@/api/home'
	export default {
		name: 'home',
		components: {
			InforCard,
			CountTo,
			ChartPie,
			ChartBar,
			Example
		},
		data() {
			return {
				inforCardData: [{
						title: '总收益',
						icon: 'logo-usd',
						count: 0,
						color: '#2d8cf0'
					},
					{
						title: '保证金',
						icon: 'logo-usd',
						count: 0,
						color: '#19be6b'
					},
					{
						title: '收益',
						icon: 'logo-usd',
						count: 0,
						color: '#ff9900'
					},
				],
				inviteData:{
					qr:'',
					code_sn:''
				}
				//    pieData: [
				//      {value: 335, name: '直接访问'},
				//      {value: 310, name: '邮件营销'},
				//      {value: 234, name: '联盟广告'},
				//      {value: 135, name: '视频广告'},
				//      {value: 1548, name: '搜索引擎'}
				//    ],
				//    barData: {
				//      Mon: 13253,
				//      Tue: 34235,
				//      Wed: 26321,
				//      Thu: 12340,
				//      Fri: 24643,
				//      Sat: 1322,
				//      Sun: 1324
				//    }
			}
		},
		mounted() {
			let t = this;
//			t.$router.push({
//	            name: 'home'
//	          })
			//t.$router.go(0)
			t.getMoneyExcute();
			t.getCodeExcute();
			
			//
		},
		methods: {
			getMoneyExcute() {
				let t = this;
				getMoney().then(res => {
					if(res.data.code == 1) {
                  let res_data = res.data.data;
                  //console.log(res_data);
                    t.inforCardData[0].count = parseFloat(res_data.zs_money);
                    t.inforCardData[1].count = parseFloat(res_data.b_money); 
                    t.inforCardData[2].count = parseFloat(res_data.s_money);
					} else {
						t.$Notice.error({
							title: res.data.msg
						})
					}

				}, function(error) {})
			},
			getCodeExcute() {
				let t = this;
				getCode().then(res => {
					if(res.data.code == 1) {
                  let res_data = res.data.data;
                  //console.log(res_data);
                   t.inviteData.qr = res_data.qr;
                   t.inviteData.code_sn = res_data.code_sn;
					} else {
						t.$Notice.error({
							title: res.data.msg
						})
					}

				}, function(error) {})
			},
			doNew(e){
				let name = e.target.getAttribute('data-type');
				 this.$router.push({
            		name: name
          		})
			}
		}
	}
</script>

<style lang="less">
	.count-style {
		font-size: 50px;
	}
</style>